package com.aaa.mythread2;

import javafx.beans.binding.When;

public class MyThreadYield {
    public static void main(String[] args) {

      Runnable runnable =   new Runnable(){

            int i=0;
            @Override
            public void run() {
                while (i<30){
                    System.out.println("当前的线程的名字是:"+Thread.currentThread().getName()+",i的值是:"+i);
                    // 如果i是5  礼让
                    if (i==5){

                        Thread.yield();
                        System.out.println("当前的线程的名字是:"+Thread.currentThread().getName()+",i的值是:"+i+"，执行礼让");
                    }
                  i++;
                }

            }
        };

        Runnable runnable1 =   new Runnable(){

            int i=0;
            @Override
            public void run() {
                while (i<30){
                    System.out.println("当前的线程的名字是:"+Thread.currentThread().getName()+",i的值是:"+i);
                    i++;
                }

            }
        };

        // 启动线程
        Thread thread = new Thread(runnable,"t1");
        Thread thread1 = new Thread(runnable1,"t2");
        thread.start();
        thread1.start();


    }
}
